package com.xuan.shop.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {
    /*
    定义exchange名称
     */
    public static final String TOPIC_EXCHANGE="my_top_exchange";
    /*
    定义两个队列名称
     */
    public static final String TOP_QUEUE_A="queue_a";
    public static final String TOP_QUEUE_B="queue_b";

    /*
    定义路由规则
     */
    public static final String ROUTING_KEY_A="apple.topic.*";
    public static final String ROUTING_KEY_B="*.topic.*";

    @Autowired
    private QueueConfig queueConfig;
    @Autowired
    private ExchangeConfig exchangeConfig;

    /**
     * 绑定topicExchange
     */
    @Bean
    public Binding bindingTopA(){
        return BindingBuilder.bind(queueConfig.topicQueueA())
                .to(exchangeConfig.topicExchange())
                .with(RabbitMqConfig.ROUTING_KEY_A);
    }
    @Bean
    public Binding bindingTopB(){
        return BindingBuilder.bind(queueConfig.topicQueueB())
                .to(exchangeConfig.topicExchange())
                .with(RabbitMqConfig.ROUTING_KEY_B);
    }
}
